<template>
  <div class="navmenu">
    <el-scrollbar class="tabbox">
      <div class="tab">
        <div
          :style="`transform: translateY(${tabId * 65}px)`"
          class="active"
        ></div>
        <div class="list">
          <div
            class="item"
            v-for="item in menuData"
            :key="item.id"
            @click="tabClick(item.path)"
          >
            <i :class="item.icon"></i>
            <span>{{ item.name }}</span>
          </div>
        </div>
      </div>
    </el-scrollbar>
    <div class="menu">
      <h2 v-if="!isCollapseMenu">{{ menuData[tabId].name }}</h2>
      <el-scrollbar class="list">
        <el-menu
          :collapse="isCollapseMenu"
          :default-active="activePath"
          class="el-menu-vertical-demo"
          router
        >
          <nav-menu-item :sub-menu="menuData[tabId]"></nav-menu-item>
        </el-menu>
      </el-scrollbar>
    </div>
  </div>
</template>

<script>
import NavMenuItem from "@/components/nav/NavMenuItem.vue";
import { defineComponent, ref, computed } from "vue";
import { useStore } from "vuex";

export default defineComponent({
  components: { NavMenuItem },
  setup() {
    const store = useStore();
    let menuData = computed(() => store.state.menuData);

    //一级路由点击
    let tabId = computed(() => store.state.tabId);
    const tabClick = (path) => {
      store.commit("setTabId", path);
    };

    return {
      menuData,
      tabId,
      activePath: computed(() => store.state.activePath),
      isCollapseMenu: computed(() => store.state.isCollapseMenu),
      tabClick,
    };
  },
});
</script>

<style lang="scss" scoped>
.navmenu {
  display: flex;
  height: 100%;
  .tabbox {
    flex: 0 0 65px;
    max-height: 100%;
    background-color: #151f2c;
    color: #fff;
    .tab {
      position: relative;
      .list {
        position: absolute;
        .item {
          display: flex;
          flex-direction: column;
          justify-content: center;
          align-items: center;
          width: 65px;
          height: 65px;
          cursor: pointer;
          i {
            font-size: 20px;
          }
          span {
            margin-top: 5px;
            font-size: 12px;
          }
        }
      }
      .active {
        position: absolute;
        width: 65px;
        height: 65px;
        background-color: #39af88;
        transition-duration: 0.5s;
      }
    }
  }

  .menu {
    display: flex;
    flex-direction: column;
    flex: 1;
    height: 100%;
    h2 {
      flex: 0 0 50px;
      padding: 0 15px;
      border-bottom: 1px solid #f0f0f0;
      line-height: 50px;
      font-size: 17px;
      font-weight: 800;
      box-sizing: border-box;
    }
    .list {
      flex: 1;
      overflow-y: auto;
    }
  }
}
</style>